<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>路由独享的守卫</title>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
</head>
<body>
    <div id="app">
        <router-link to="/one">one组件</router-link>
        <router-link to="/two">two组件</router-link>
        <router-view></router-view>
    </div>
    <script>
        /* 
            历史模式：路由器实际网页结构，当在url上手动输入组件名时，找不到页面，出现404
            原理：
            怎么解决


        
        
        */
        const MyOne={template:`<div>组件一</div>`};
        const MyTwo={template:`<div>组件二</div>`};

        const routes = [
            {
                path:"/one",
                component:MyOne,
            },
            {
                path:"/two",
                component:MyTwo,
                // 路由独享的守卫
                beforeEnter: (to, from, next) => {
                    console.log(to);
                    console.log(from);
                    next();
                }
            },
        ];

        const router = new VueRouter({
            routes,
        });

        const app = new Vue({
            el:"#app",
            router,
        })
    </script>
</body>
</html>